﻿package server;

import java.rmi.RemoteException;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ComHouse {

	private Data data;
	/*
	public int houseNum;
	public String kind;
	private String key;
	public int ownID;
	*/
	public ComHouse(){
		data=new Data();
		
	}
	

	public String getKind(int id)throws RemoteException{
		
		String sql;
		ResultSet rs=null;
		String kind=null;
		
		sql="select * from combuylist where id=" + id;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				kind=rs.getString("housekind");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
		return kind;
	}
	
	public String getKey(int id)throws RemoteException{
		String sql;
		ResultSet rs=null;
		String key=null;
		
		sql="select * from comhouselist where id=" + id;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				key=rs.getString("key");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
		return key;
	}
	
	public int getOwnID(int id)throws RemoteException{
		String sql;
		ResultSet rs=null;
		int onwerId=0;
		
		sql="select * from comhouselist where id=" + id;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				onwerId=rs.getInt("onwerId");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
	
		return onwerId;
	}
	
	public boolean setKind(int id,String ki)throws RemoteException{
		String sql;
		int re=0;
		
		sql="update combuylist set housekind = "+ki+"where id="+id;
		re=data.update(sql);
		
		if(re==1){
			return true;
		}
		return false;
	
	}
	
	public boolean setKey(int id,String k)throws RemoteException{
		String sql;
		int re=0;
		
		sql="update comhouselist set key = "+k+"where id="+id;
		re=data.update(sql);
		
		if(re==1){
			return true;
		}
		return false;
		
	}
	
	public boolean setOwnID(int id,int oi)throws RemoteException{
		String sql;
		int re=0;
		
		sql="update comhouselist set onwerId = "+oi+"where id="+id;
		re=data.update(sql);
		
		if(re==1){
			return true;
		}
		return false;
	
	}
	

}
